/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSkyRoom.factory;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import ru.jSkyRoom.bridge.JSkyBridge;
import ru.jSkyRoom.bridge.ModBridge;
import ru.jSkyRoom.bridge.major.ActorValueBridge;
import ru.jSkyRoom.bridge.major.AmmoBridge;
import ru.jSkyRoom.bridge.major.ArmatureBridge;
import ru.jSkyRoom.bridge.major.ArmorBridge;
import ru.jSkyRoom.bridge.major.AttackDataBridge;
import ru.jSkyRoom.bridge.major.BookBridge;
import ru.jSkyRoom.bridge.major.ContainerBridge;
import ru.jSkyRoom.bridge.major.DialogBranchBridge;
import ru.jSkyRoom.bridge.major.DialogBridge;
import ru.jSkyRoom.bridge.major.EnchantmentBridge;
import ru.jSkyRoom.bridge.major.EncounterZoneBridge;
import ru.jSkyRoom.bridge.major.FactionBridge;
import ru.jSkyRoom.bridge.major.FormListBridge;
import ru.jSkyRoom.bridge.major.GameSettingBridge;
import ru.jSkyRoom.bridge.major.GlobalFormBridge;
import ru.jSkyRoom.bridge.major.HeadPartBridge;
import ru.jSkyRoom.bridge.major.ImageSpaceBridge;
import ru.jSkyRoom.bridge.major.InfoBridge;
import ru.jSkyRoom.bridge.major.IngredientBridge;
import ru.jSkyRoom.bridge.major.KeywordBridge;
import ru.jSkyRoom.bridge.major.LeveledCharacterBridge;
import ru.jSkyRoom.bridge.major.LeveledItemListBridge;
import ru.jSkyRoom.bridge.major.LightBridge;
import ru.jSkyRoom.bridge.major.LightTemplateBridge;
import ru.jSkyRoom.bridge.major.MagicEffectBridge;
import ru.jSkyRoom.bridge.major.MiscellaneousBridge;
import ru.jSkyRoom.bridge.major.NPCBridge;
import ru.jSkyRoom.bridge.major.OutfitBridge;
import ru.jSkyRoom.bridge.major.PerkBridge;
import ru.jSkyRoom.bridge.major.PotionBridge;
import ru.jSkyRoom.bridge.major.ProjectileBridge;
import ru.jSkyRoom.bridge.major.QuestBridge;
import ru.jSkyRoom.bridge.major.RaceBridge;
import ru.jSkyRoom.bridge.major.RecipeBridge;
import ru.jSkyRoom.bridge.major.ScrollBridge;
import ru.jSkyRoom.bridge.major.SpellBridge;
import ru.jSkyRoom.bridge.major.TextureBridge;
import ru.jSkyRoom.bridge.major.WeaponBridge;
import ru.jSkyRoom.bridge.sub.AltTextureBridge;
import ru.jSkyRoom.bridge.sub.ArmatureGenderSettinsBridge;
import ru.jSkyRoom.bridge.sub.BodyTemplateBridge;
import ru.jSkyRoom.bridge.sub.LeveledEntryBridge;
import ru.jSkyRoom.bridge.sub.MagicEffectReferenceBridge;
import ru.jSkyRoom.bridge.sub.PerkLinkBridge;
import ru.jSkyRoom.bridge.sub.QuestLogEntryBridge;
import ru.jSkyRoom.bridge.sub.QuestStageBridge;
import ru.jSkyRoom.bridge.sub.ResponseBridge;
import ru.jSkyRoom.bridge.sub.ScriptPackageBridge;
import ru.jSkyRoom.bridge.sub.model.ArmatureModelBridge;
import ru.jSkyRoom.bridge.sub.model.ArmorModelBridge;
import ru.jSkyRoom.bridge.sub.model.ModelBridge;
import ru.jSkyRoom.interfaces.stub.JSkyScriptPackage;
import ru.jSkyRoom.interfaces.sub.ArmatureGenderSettings;
import ru.jSkyRoom.interfaces.sub.JSkyBodyTemplate;
import ru.jSkyRoom.interfaces.sub.JSkyModel;
import ru.jSkyRoom.interfaces.sub.MagicEffectReference;
import ru.jSkyRoom.interfaces.support.NullArgumentPermitted;
import skyproc.ALCH;
import skyproc.AMMO;
import skyproc.ARMA;
import skyproc.ARMO;
import skyproc.AVIF;
import skyproc.AVIF.PerkReference;
import skyproc.AltTextures;
import skyproc.BOOK;
import skyproc.BodyTemplate;
import skyproc.COBJ;
import skyproc.CONT;
import skyproc.DIAL;
import skyproc.DLBR;
import skyproc.ECZN;
import skyproc.ENCH;
import skyproc.FACT;
import skyproc.FLST;
import skyproc.GLOB;
import skyproc.GMST;
import skyproc.HDPT;
import skyproc.IMGS;
import skyproc.INFO;
import skyproc.INGR;
import skyproc.KYWD;
import skyproc.LGTM;
import skyproc.LIGH;
import skyproc.LVLI;
import skyproc.LVLN;
import skyproc.LeveledEntry;
import skyproc.MGEF;
import skyproc.MISC;
import skyproc.MagicEffectRef;
import skyproc.Mod;
import skyproc.Model;
import skyproc.NPC_;
import skyproc.OTFT;
import skyproc.PERK;
import skyproc.PROJ;
import skyproc.QUST;
import skyproc.RACE;
import skyproc.RACE.AttackData;
import skyproc.SCRL;
import skyproc.SPEL;
import skyproc.ScriptPackage;
import skyproc.TXST;
import skyproc.WEAP;
import skyproc.genenums.Gender;
import skyproc.genenums.Perspective;

/**
 *
 * @author Rakev
 */
public class BridgeFactory {

    private static BridgeFactory instance = new BridgeFactory();

    public static BridgeFactory create() {
        return instance;
    }

    protected BridgeFactory() {
    }

    public <E> Collection<JSkyBridge<E>> createBridges(Collection<E> records) {
        return createBridges(records, JSkyBridge.class);
    }

    public <E, T extends JSkyBridge<E>> Collection<T> createBridges(Collection<E> records, Class<T> returnedClass) {
        List<T> adapters = new ArrayList<>(records.size());
        for (E record : records) {
            T adapter = createBridge(record, returnedClass);
            adapters.add(adapter);
        }
        return adapters;
    }

    public <E> JSkyBridge<E> createBridge(E record) {
        return createBridge(record, JSkyBridge.class);
    }

    public <E, T extends JSkyBridge<E>> T createBridge(E record, Class<T> returnedClass) {
        if (record instanceof ENCH) {
            return (T) createBridge((ENCH) record);
        }
        if (record instanceof ARMO) {
            return (T) createBridge((ARMO) record);
        }
        if (record instanceof WEAP) {
            return (T) createBridge((WEAP) record);
        }
        if (record instanceof ALCH) {
            return (T) createBridge((ALCH) record);
        }
        if (record instanceof AMMO) {
            return (T) createBridge((AMMO) record);
        }
        if (record instanceof ARMA) {
            return (T) createBridge((ARMA) record);
        }
        if (record instanceof SPEL) {
            return (T) createBridge((SPEL) record);
        }
        if (record instanceof FLST) {
            return (T) createBridge((FLST) record);
        }
        if (record instanceof LVLI) {
            return (T) createBridge((LVLI) record);
        }
        if (record instanceof LVLN) {
            return (T) createBridge((LVLN) record);
        }
        if (record instanceof KYWD) {
            return (T) createBridge((KYWD) record);
        }
        if (record instanceof BOOK) {
            return (T) createBridge((BOOK) record);
        }
        if (record instanceof RACE) {
            return (T) createBridge((RACE) record);
        }
        if (record instanceof TXST) {
            return (T) createBridge((TXST) record);
        }
        if (record instanceof AVIF) {
            return (T) createBridge((AVIF) record);
        }
        if (record instanceof PERK) {
            return (T) createBridge((PERK) record);
        }
        if (record instanceof COBJ) {
            return (T) createBridge((COBJ) record);
        }
        if (record instanceof CONT) {
            return (T) createBridge((CONT) record);
        }
        if (record instanceof DIAL) {
            return (T) createBridge((DIAL) record);
        }
        if (record instanceof DLBR) {
            return (T) createBridge((DLBR) record);
        }
        if (record instanceof QUST) {
            return (T) createBridge((QUST) record);
        }
        if (record instanceof INFO) {
            return (T) createBridge((INFO) record);
        }
        if (record instanceof ECZN) {
            return (T) createBridge((ECZN) record);
        }
        if (record instanceof NPC_) {
            return (T) createBridge((NPC_) record);
        }
        if (record instanceof FACT) {
            return (T) createBridge((FACT) record);
        }
        if (record instanceof GLOB) {
            return (T) createBridge((GLOB) record);
        }
        if (record instanceof GMST) {
            return (T) createBridge((GMST) record);
        }
        if (record instanceof HDPT) {
            return (T) createBridge((HDPT) record);
        }
        if (record instanceof IMGS) {
            return (T) createBridge((IMGS) record);
        }
        if (record instanceof INGR) {
            return (T) createBridge((INGR) record);
        }
        if (record instanceof LGTM) {
            return (T) createBridge((LGTM) record);
        }
        if (record instanceof LIGH) {
            return (T) createBridge((LIGH) record);
        }
        if (record instanceof MGEF) {
            return (T) createBridge((MGEF) record);
        }
        if (record instanceof MISC) {
            return (T) createBridge((MISC) record);
        }
        if (record instanceof OTFT) {
            return (T) createBridge((OTFT) record);
        }
        if (record instanceof PROJ) {
            return (T) createBridge((PROJ) record);
        }
        if (record instanceof SCRL) {
            return (T) createBridge((SCRL) record);
        }
        if (record instanceof LeveledEntry) {
            return (T) createBridge((LeveledEntry) record);
        }
        if (record instanceof Mod) {
            return (T) createBridge((Mod) record);
        }
        if (record instanceof AltTextures.AltTexture) {
            return (T) createBridge((AltTextures.AltTexture) record);
        }
        if (record instanceof ScriptPackage) {
            return (T) createBridge((ScriptPackage) record);
        }
        if (record instanceof BodyTemplate) {
            return (T) createBridge((BodyTemplate) record);
        }
        if (record instanceof MagicEffectRef) {
            return (T) createBridge((MagicEffectRef) record);
        }
        if (record instanceof Model) {
            return (T) createBridge((Model) record);
        }
        if (record instanceof PerkReference) {
            return (T) createBridge((PerkReference) record);
        }
        if (record instanceof INFO.Response) {
            return (T) createBridge((INFO.Response) record);
        }
        if (record instanceof QUST.QuestLogEntry) {
            return (T) createBridge((QUST.QuestLogEntry) record);
        }
        if (record instanceof QUST.QuestStage) {
            return (T) createBridge((QUST.QuestStage) record);
        }
        if (record instanceof AttackData) {
            return (T) createBridge((AttackData) record);
        }
        throw new IllegalArgumentException("" + record.getClass() + " not supported yet.");
    }

    public EnchantmentBridge createBridge(ENCH enchantment) {
        return new EnchantmentBridge(enchantment);
    }

    public ArmorBridge createBridge(ARMO armo) {
        return new ArmorBridge(armo);
    }

    public WeaponBridge createBridge(WEAP weap) {
        return new WeaponBridge(weap);
    }

    public ArmatureBridge createBridge(ARMA armature) {
        return new ArmatureBridge(armature);
    }

    public FormListBridge createBridge(FLST flst) {
        return new FormListBridge(flst);
    }

    public LeveledItemListBridge createBridge(LVLI leveledItemList) {
        return new LeveledItemListBridge(leveledItemList);
    }

    public LeveledCharacterBridge createBridge(LVLN record) {
        return new LeveledCharacterBridge(record);
    }

    public KeywordBridge createBridge(KYWD keyword) {
        return new KeywordBridge(keyword);
    }

    public RaceBridge createBridge(RACE race) {
        return new RaceBridge(race);
    }

    public TextureBridge createBridge(TXST texture) {
        return new TextureBridge(texture);
    }

    public AmmoBridge createBridge(AMMO ammo) {
        return new AmmoBridge(ammo);
    }

    public PotionBridge createBridge(ALCH potion) {
        return new PotionBridge(potion);
    }

    public ActorValueBridge createBridge(AVIF record) {
        return new ActorValueBridge(record);
    }

    public BookBridge createBridge(BOOK record) {
        return new BookBridge(record);
    }

    public PerkBridge createBridge(PERK record) {
        return new PerkBridge(record);
    }

    public SpellBridge createBridge(SPEL record) {
        return new SpellBridge(record);
    }

    public RecipeBridge createBridge(COBJ record) {
        return new RecipeBridge(record);
    }

    public ContainerBridge createBridge(CONT record) {
        return new ContainerBridge(record);
    }

    public DialogBridge createBridge(DIAL record) {
        return new DialogBridge(record);
    }

    public DialogBranchBridge createBridge(DLBR record) {
        return new DialogBranchBridge(record);
    }

    public QuestBridge createBridge(QUST record) {
        return new QuestBridge(record);
    }

    public InfoBridge createBridge(INFO record) {
        return new InfoBridge(record);
    }

    public NPCBridge createBridge(NPC_ record) {
        return new NPCBridge(record);
    }

    public FactionBridge createBridge(FACT record) {
        return new FactionBridge(record);
    }

    public EncounterZoneBridge createBridge(ECZN record) {
        return new EncounterZoneBridge(record);
    }

    public GlobalFormBridge createBridge(GLOB record) {
        return new GlobalFormBridge(record);
    }

    public GameSettingBridge createBridge(GMST record) {
        return new GameSettingBridge(record);
    }

    public HeadPartBridge createBridge(HDPT record) {
        return new HeadPartBridge(record);
    }

    public ImageSpaceBridge createBridge(IMGS record) {
        return new ImageSpaceBridge(record);
    }

    public IngredientBridge createBridge(INGR record) {
        return new IngredientBridge(record);
    }

    public LightTemplateBridge createBridge(LGTM record) {
        return new LightTemplateBridge(record);
    }

    public LightBridge createBridge(LIGH record) {
        return new LightBridge(record);
    }

    public MagicEffectBridge createBridge(MGEF record) {
        return new MagicEffectBridge(record);
    }

    public MiscellaneousBridge createBridge(MISC record) {
        return new MiscellaneousBridge(record);
    }

    public OutfitBridge createBridge(OTFT record) {
        return new OutfitBridge(record);
    }

    public ProjectileBridge createBridge(PROJ record) {
        return new ProjectileBridge(record);
    }

    public ScrollBridge createBridge(SCRL record) {
        return new ScrollBridge(record);
    }

    public LeveledEntryBridge createBridge(LeveledEntry leveledEntry) {
        return new LeveledEntryBridge(leveledEntry);
    }

    public ModBridge createBridge(Mod mod) {
        return new ModBridge(mod);
    }

    @NullArgumentPermitted
    public JSkyScriptPackage createBridge(ScriptPackage scriptPackage) {
        if (scriptPackage == null) {
            return null;
        }
        return new ScriptPackageBridge(scriptPackage);

    }

    @NullArgumentPermitted
    public JSkyBodyTemplate createBridge(BodyTemplate bodyTemplate) {
        if (bodyTemplate == null) {
            return null;
        }
        return new BodyTemplateBridge(bodyTemplate);
    }

    @NullArgumentPermitted
    public MagicEffectReference createBridge(MagicEffectRef magicEffect) {
        if (magicEffect == null) {
            return null;
        }
        return new MagicEffectReferenceBridge(magicEffect);
    }

    public AltTextureBridge createBridge(AltTextures.AltTexture altTexture) {
        return new AltTextureBridge(altTexture);
    }

    public JSkyModel createBridge(ArmorBridge armor, Gender gender) {
        return new ArmorModelBridge(armor.getRawObject(), gender);
    }

    public ArmatureGenderSettings createGenderSettingsBridge(ArmatureBridge armature, Gender gender) {
        return new ArmatureGenderSettinsBridge(armature.getRawObject(), gender);
    }

    public JSkyModel createBridge(ArmatureBridge armature, Gender gender, Perspective perspective) {
        return new ArmatureModelBridge(armature.getRawObject(), gender, perspective);
    }

    public JSkyModel createBridge(Model model) {
        if (model == null) {
            return null;
        }
        return new ModelBridge(model);
    }

    public PerkLinkBridge createBridge(PerkReference record) {
        return new PerkLinkBridge(record);
    }

    public ResponseBridge createBridge(INFO.Response record) {
        return new ResponseBridge(record);
    }

    public QuestLogEntryBridge createBridge(QUST.QuestLogEntry record) {
        return new QuestLogEntryBridge(record);
    }

    public QuestStageBridge createBridge(QUST.QuestStage record) {
        return new QuestStageBridge(record);
    }

    public AttackDataBridge createBridge(AttackData record) {
        return new AttackDataBridge(record);
    }
}
